package Log::Console;

use JIP::ToolSet; # load my commonly-used modules in a single import
use parent qw( Log );

use IO::Handle;
use Carp qw( croak );
use English qw( -no_match_vars );

__PACKAGE__->mk_ro_accessors( qw( _logLevel _outputHandle _outputBuffering ) );

sub init {
    my( $self, $config ) = @ARG;

    $self->{'_logLevel'} = $config->{'log_level'}
        or croak('required parameter "log_level" not defined');

    $self->{'_outputBuffering'} = $config->{'buffering'} || undef;

    $self->{'_outputHandle'} = IO::Handle->new;

    croak('STDOUT problem')
        unless $self->{'_outputHandle'}->fdopen( fileno(STDOUT), "w" );

    $self->{'_outputHandle'}->autoflush unless $self->{'_outputBuffering'};

    binmode( $self->{'_outputHandle'}, ':utf8' );

    return $self;
}

1;
